package com.ubiquando.api.server.db;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.Basic;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;

import com.google.appengine.api.datastore.Key;


@Entity
@MappedSuperclass
public abstract class Event {
	
	public static final int MEETING_EVENT = 0;
	public static final int PICKUP_EVENT = 1;
	
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	protected Key id;
	
	protected int type;
	
	protected String name;
	
	protected long time;
	
	protected String dest;
	
//	protected String destName;
	
	//@Basic
//	@OneToOne
//	protected Client creator;
	
	protected String creatorId;
	
	protected boolean started;	

//	@JoinTable
	//@ElementCollection/*(fetch=FetchType.EAGER)*/
	@Basic
	protected Set<String> participants;
	
	public Event(){
		this.participants = new HashSet<String>();
	}
	
	//@Basic
//	@ManyToMany(mappedBy = "name")
//	protected Set<Client> participants;
	
//	public Event(int type, String name, Client creator, long time, String destination){
//		this.type = type;
//		this.name = name;
//		this.creator = creator;
//		this.started = false;
//		this.time = new Date(time);
//		this.dest = destination;
//		this.participants = new HashSet<Client>();
//		this.participants.add(this.getCreator());
//	}
	
	public Key getId(){
		return this.id;
	}
	
	public int getType(){
		return this.type;
	}
	
	public void setType(int type){
		this.type = type;
	}
	
	public String getName(){
		return this.name;
	}
	
	public void setName(String name){
		this.name = name;
	}
	
	public long getTime(){
		return this.time;
	}
	
	public void setTime(long time){
		this.time = time;
	}
	
	public String getDest(){
		return this.dest;
	}
	
	public void setDest(String destination){
		this.dest = destination;
	}
	
//	public String getDestName(){
//		return this.destName;
//	}
//	
//	public void setDestName(String destination){
//		this.destName = destination;
//	}
	
	public String getCreatorId(){
		return this.creatorId;
	}
	
	public void setCreatorId(String ownerId){
		this.creatorId = ownerId;
	}
	
	public boolean isStarted(){
		return this.started;
	}
	
	public void setStarted(boolean started){
		this.started = started;
	}
	
//	public abstract Set<String> getParticipants();
//	
//	public abstract void setParticipants(Set<String> participants);
//	
//	public abstract void addParticipant(String clientID);
//	
//	public abstract void removeParticipant(String clientId);
	
	public Set<String> getParticipants(){
		return this.participants;
	}
	
	public void setParticipants(Set<String> participants){
		this.participants = participants;
	}
	
	public void addParticipant(String clientId){
//		if(this.participants == null)
//			this.participants = new HashSet<String>();
		this.participants.add(clientId);
	}
	
//	@Basic
	public void removeParticipant(String clientId){
//		if(this.participants != null){
			this.participants.remove(clientId);
//		}
	}
}
